package com.eight.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eight.order.dao.OrderDao;
import com.eight.order.pojo.Order;
import com.eight.order.pojo.OrderPayLog;
import com.eight.order.service.OrderService;
import com.eight.order.vo.OrderVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * @program: qy8-education
 * @description:
 * @author: 郑友民（1460115388@qq.com）
 * @create: 2023-05-26 16:12
 **/
@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderDao orderDao;


    @Override
    public Page<Order> getAllOrder(Integer current, Integer pageSize, OrderVo orderVo) {
        Page<Order> page = new Page<>(current, pageSize);
        QueryWrapper<Order> wrapper = new QueryWrapper<>();
        if (StringUtils.hasText(orderVo.getOrderNo())) {
            wrapper.like("o.order_no", orderVo.getOrderNo());
        }
        if (StringUtils.hasText(orderVo.getCourseTitle())) {
            wrapper.like("o.course_title", orderVo.getCourseTitle());
        }
        if (StringUtils.hasText(orderVo.getTeacherName())) {
            wrapper.like("o.teacher_name", orderVo.getTeacherName());
        }
        if (StringUtils.hasText(orderVo.getMobile())) {
            wrapper.like("o.mobile", orderVo.getMobile());
        }
        if (orderVo.getPayType() != null) {
            wrapper.eq("o.pay_type", orderVo.getPayType());
        }
        if (orderVo.getStatus() != null) {
            wrapper.eq("o.status", orderVo.getStatus());
        }
        if (orderVo.getGmtCreate() != null) {
            wrapper.ge("tpl.pay_time", orderVo.getGmtCreate());
        }
        if (orderVo.getGmtModified() != null) {
            wrapper.le("tpl.pay_time", orderVo.getGmtModified());
        }
        orderDao.findPage(page, wrapper);
        return page;
    }

    @Override
    public OrderPayLog queryOrderAndPayLog(String id) {
        OrderPayLog orderPayLogs = orderDao.queryOrderAndPayLog(id);
        if (orderPayLogs.getStatus() == 0) {
            orderPayLogs.setPayTime(null);
        }
        return orderPayLogs;
    }
}

